#define _CRT_SECURE_NO_WARNINGS   1

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
class Solution
{
public:
	int minTrace(vector<vector<int> >& triangle)
	{
		int size = triangle.size();
		vector<int> dp(size + 1, 0);
		for (int i = size - 1; i >= 0; i--)
		{
			for (int j = 0; j <= i; j++)
			{
				dp[j] = min(dp[j], dp[j + 1]) + triangle[i][j];
			}
		}
		return dp[0];
	}
};
int main()
{
	vector<vector<int>>a;
	int num;
	vector<int>b;
	a.clear();
	while (1)
	{
		b.clear();
		while (cin.get() != '\n')
		{
			cin >> num;
			b.push_back(num);
		}
		a.push_back(b);
		if (cin.get() == '*')
			break;
	}
	Solution sol;
	cout << sol.minTrace(a) << endl;
	return 0;
}